﻿using System;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DotNetNuke;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Services.Localization;
using DotNetNuke.Services.Exceptions;
using gdlmo.DNN.Modules.Article.Business;

namespace gdlmo.DNN.Modules.Article
{
	public abstract class CategoryList : PortalModuleBase, IActionable, IPortable, ISearchable 
	{
		protected System.Web.UI.WebControls.DataGrid grdCategories;
		
		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		///		Required method for Designer support - do not modify
		///		the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		#region Private Function
		protected bool MyIsEditable(string CreatedByUser)
		{
			if(UserInfo.UserID != -1)
			{
				if(UserInfo.Username.ToLower().CompareTo(CreatedByUser.ToLower())==0 || DotNetNuke.Security.PortalSecurity.IsInRole("Administrators") )
				{
					return true;
				}
			}
			return false;
		}
		
		#endregion
		#region Event Handlers

		private void Page_Load(object sender, System.EventArgs e)
		{
			try 
			{
				CategoryController objCategory = new CategoryController();
				ArrayList list;
				if (!Page.IsPostBack) 
				{
					list = objCategory.GetByModules(ModuleId);
					grdCategories.DataSource = list;
					grdCategories.DataBind();
				}
			} 
			catch (Exception exc) 
			{
				Exceptions.ProcessModuleLoadException(this, exc);
			}
		}

		#endregion

		#region Optional Interfaces

		public DotNetNuke.Entities.Modules.Actions.ModuleActionCollection ModuleActions 
		{
			get 
			{
				DotNetNuke.Entities.Modules.Actions.ModuleActionCollection Actions = new DotNetNuke.Entities.Modules.Actions.ModuleActionCollection();
				Actions.Add(GetNextActionID(), Localization.GetString("ArticlesManager.Text", LocalResourceFile), DotNetNuke.Entities.Modules.Actions.ModuleActionType.AddContent, "", "", Globals.NavigateURL(), false, DotNetNuke.Security.SecurityAccessLevel.View, true, false);
				Actions.Add(GetNextActionID(), Localization.GetString(DotNetNuke.Entities.Modules.Actions.ModuleActionType.AddContent, LocalResourceFile), DotNetNuke.Entities.Modules.Actions.ModuleActionType.AddContent, "", "", EditUrl("CategoryEdit"), false, DotNetNuke.Security.SecurityAccessLevel.Edit, true, false);
//				Actions.Add(GetNextActionID(), Localization.GetString("CategoriesManager.Text",LocalResourceFile), DotNetNuke.Entities.Modules.Actions.ModuleActionType.AddContent, "", "", EditUrl("CategoryEdit"), false, DotNetNuke.Security.SecurityAccessLevel.Edit, true, false);
				
				return Actions;
			}
		}

		public string ExportModule(int ModuleID)
		{
			// included as a stub only so that the core knows this module Implements Entities.Modules.IPortable
			return null;
		}

		public void ImportModule(int ModuleID, string Content, string Version, int UserID)
		{
			// included as a stub only so that the core knows this module Implements Entities.Modules.IPortable
		}

		public DotNetNuke.Services.Search.SearchItemInfoCollection GetSearchItems(ModuleInfo ModInfo)
		{
			// included as a stub only so that the core knows this module Implements Entities.Modules.ISearchable
			return null;
		}

		#endregion

	}
}